package com.ccit.integral.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccit.common.exception.GymException;
import com.ccit.common.utils.RedisUtils;
import com.ccit.integral.service.IntegralGoodsService;
import com.ccit.integral.service.IntegralRecordService;
import com.ccit.integral.service.impl.IntegralServiceImpl;
import com.ccit.model.Integral;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "积分调用接口")
@RestController
@RequestMapping("/integral/api")
public class IntegralApiController {
    @Autowired
    private IntegralServiceImpl integralService;
    @Autowired
    private IntegralGoodsService integralGoodsService;
    @Autowired
    private IntegralRecordService integralRecordService;

    @Autowired
    private RedisUtils redisUtils;

   /* @ApiOperation(value = "修改积分")
    @PostMapping("/updateIntegral")
    public Boolean updateIntegral(@RequestBody Integral integral) {
            QueryWrapper<Integral> wrapper = new QueryWrapper<Integral>();
            wrapper.lambda()
                    .eq(Integral::getPhone,integral.getPhone());
            Integral one = integralService.getOne(wrapper);
            if (one==null){
                boolean save = integralService.save(integral);
                if (!save){
                    throw new GymException(230,"添加积分出错");
                }
                redisUtils.deleteRedisKeys("IntegralPage");
                redisUtils.deleteRedisKeys("AllIntegral");
                redisUtils.deleteRedisKeys("IntegralExchangePage");
                return true;
            }
            else {
                one.setIntegral(one.getIntegral()+integral.getIntegral());
                boolean flag = integralService.updateById(one);
                if (flag) {
                    redisUtils.deleteRedisKeys("IntegralPage");
                    redisUtils.deleteRedisKeys("AllIntegral");
                    redisUtils.deleteRedisKeys("IntegralExchangePage");
                    return true;
                } else {
                    return false;
                }
            }
    }*/
}
